<?php echo $this->render('/public/header'); ?>
    <script src="/statics/utils/common.js"></script>
    <style type="text/css">
        .container.box {
            padding:20px;
        }

        #my-title {
            font-size: 16px;
            font-weight: bold;
            line-height: 32px;
            padding-right: 20px;
            float: left;
        }

        .search {
            margin: 30px 0;
        }

        .search .el-input {
            width: 180px;
            margin-right: 15px;
        }
        .search .el-input--suffix .el-input__inner{
            margin-bottom: 10px;
        }
        .search .el-input__prefix, .el-input__suffix{
            top: -4px;
        }

        .el-pagination {
            margin-top: 30px;
        }

        .post_sample .el-form-item {
            width: 50%;
            float: left;
        }

        .el-form-item.full {
            width: 100%;
        }

        .press_price_table {
            width: 100%;
            background: #f4f4f5;
        }

        .press_price_table tr td {
            text-align: center;
        }

        .press_price_table tr td button {
            width: 100%;
        }
        .el-button+.el-button{margin:5px;}
        .cell button{margin:5px;}
        .el-dialog{
            margin-top:6vh!important;
            width: 80%;
        }
        .add-long-input .el-form-item__content .el-autocomplete{
            width:100%;
        }
        .addData-dialog::-webkit-scrollbar{
            display: none;
            position: relative;
        }
        .flex{
            display: flex;
            align-items: center;
        }
        input::-webkit-outer-spin-button,input::-webkit-inner-spin-button{
            -webkit-appearance: none !important;
        }
        input[type="number"]{-moz-appearance:textfield;}
        .el-input.is-disabled .el-input__inner{
            color: #000;
        }
        .el-select-dropdown__item.selected{
            color: #000;
        }
        .el-dialog__body{
            padding: 30px 40px;
        }
		.el-timeline{
		  height: 200px;
		  overflow-y: auto;
		  padding-top: 5px;
		}
        .el-button--text{color: #606266;}
    </style>
    <div class="container box">
        <div id="app">
            <el-row>
                <h1 id="my-title">样品寄件列表</h1>
                <el-button type="primary" size="small" v-if="isSaleMan" @click="postData">申请寄件</el-button>
            </el-row>
            <el-dialog
                class="addData-dialog"
                title="样品寄件表格"
                :visible.sync="applyLogisticsDialogForm"
                ref="addData_dialog" @open="applyDialogFormOpen()"
                @closed="applyDialogFormClose()"
                :close-on-click-modal="false"
                :lock-scroll="false">
                <el-form :model="addData" v-loading="addDataLoading" :rules="addData.rules" class="post_sample" element-loading-text="正在提交中,请稍后...">
                    <el-tabs type="card" v-model="tabscard">
                        <el-tab-pane label="货物重量" name="first">
                            <el-form-item label="长" prop="long" :label-width="formLabelWidth" style="width:33%;">
                                <el-input v-model="addData.long" :disabled="applyLogisticsDialogFormState==-2" >
                                    <template slot="append">cm</template>
                                </el-input>
                            </el-form-item>
                            <el-form-item label="宽" prop="width" :label-width="formLabelWidth" style="width:33%;">
                                <el-input v-model="addData.width" :disabled="applyLogisticsDialogFormState==-2">
                                    <template slot="append">cm</template>
                                </el-input>
                            </el-form-item>
                            <el-form-item label="高" prop="height" :label-width="formLabelWidth" style="width:33%;">
                                <el-input v-model="addData.height" :disabled="applyLogisticsDialogFormState==-2">
                                    <template slot="append">cm</template>
                                </el-input>
                            </el-form-item>
                            <el-form-item label="体积重" :label-width="formLabelWidth" style="width:33%;">
                                <el-input v-model="addData.weight" :disabled="true">
                                    <template slot="append">KG</template>
                                </el-input>
                            </el-form-item>
                            <el-form-item label="货物实重" prop="real_weight" :label-width="formLabelWidth"style="width:33%;">
                                <el-input v-model="addData.real_weight"  :disabled="applyLogisticsDialogFormState==-2"  >
                                    <template slot="append">KG</template>
                                </el-input>
                            </el-form-item>
                            <el-form-item label="计重" :label-width="formLabelWidth" style="width:33%;">
                                <el-input v-model="addData.press_weight"   :disabled="true">
                                    <template slot="append">KG</template>
                                </el-input>
                            </el-form-item>
                        </el-tab-pane>
                    </el-tabs>
                    <el-tabs type="card" v-model="tabscard">
                        <el-tab-pane label="寄件信息" name="first">
                            <el-form-item label="客户名称"  prop="customer_name" :label-width="formLabelWidth" class="add-long-input" style="width:33%;">
                                <el-select v-model="addData.customer_name" filterable @change="handleSelectCustomer" @focus="querySearchCustomer('',1)" :filter-method="getrealCustomer" style="width:100%" :disabled="applyLogisticsDialogFormState==-2 || applyLogisticsDialogFormState==-3"  placeholder="请选择">
                                    <el-option
                                            v-for="item in searchCustomerList"
                                            :key="item.id"
                                            :label="item.customer_name"
                                            :value="item">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="客户编号" prop="customer_number" :label-width="formLabelWidth" style="width:33%;">
                                <el-input v-model="addData.customer_number" :disabled="true"></el-input>
                            </el-form-item>
                            <el-form-item label="收件人姓名" prop="press_name" :label-width="formLabelWidth" style="width:33%;">
                                <el-input v-model="addData.press_name"  :disabled="applyLogisticsDialogFormState==-2 || applyLogisticsDialogFormState==-3"></el-input>
                            </el-form-item>
                            <el-form-item label="收件人国家" prop="region_name" :label-width="formLabelWidth" style="width:33%;" class="add-long-input">
                                <el-select v-model="addData.region_name" style="width:100%" filterable @change="handleSelectCountry" @focus="remakeCountry" :filter-method="getrealCountry" :disabled="applyLogisticsDialogFormState==-2 || applyLogisticsDialogFormState==-3"  placeholder="请选择">
                                    <el-option
                                            v-for="item in searchCountryList"
                                            :key="item.id"
                                            :label="item.value"
                                            :value="item">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="收件人地区" prop="province_name" :label-width="formLabelWidth"  style="width:33%;">
                                <el-input v-model="addData.province_name"  :disabled="applyLogisticsDialogFormState==-2 || applyLogisticsDialogFormState==-3" placeholder="省份/州" style="width:49%;"></el-input>
                                <el-input v-model="addData.city_name"  :disabled="applyLogisticsDialogFormState==-2 || applyLogisticsDialogFormState==-3" placeholder="城市" style="width:49%;"></el-input>
                            </el-form-item>
                            <el-form-item label="收件人电话" prop="press_tel" :label-width="formLabelWidth"  style="width:33%;">
                                <el-input v-model="addData.press_tel" :disabled="applyLogisticsDialogFormState==-2 || applyLogisticsDialogFormState==-3"  >
                                    <template slot="prepend">{{ addData.numberCode?'+'+addData.numberCode+'-':'' }}</template>
                                </el-input>
                            </el-form-item>
                            <el-form-item label="详细地址" prop="press_addr" :label-width="formLabelWidth" style="width:66%;">
                                <el-input v-model="addData.press_addr" :disabled="applyLogisticsDialogFormState==-2 || applyLogisticsDialogFormState==-3" ></el-input>
                            </el-form-item>
                            <el-form-item label="邮编" prop="post_code" :label-width="formLabelWidth" style="width:33%;">
                                <el-input v-model="addData.post_code" :disabled="applyLogisticsDialogFormState==-2 || applyLogisticsDialogFormState==-3"    style="width:80%;"></el-input>
                            </el-form-item>
                            <el-form-item label="备注"  :label-width="formLabelWidth" style="width:33%;">
                                <el-input
                                type="textarea"
                                :autosize="{ minRows: 2, maxRows: 4}"
                                :disabled="applyLogisticsDialogFormState==-2"
                                placeholder="请输入相关备注"
                                v-model="addData.comment">
                                </el-input>
                            </el-form-item>
                            <el-form-item label="邮件收件人" :label-width="formLabelWidth" class="label-required add-long-input" style="width:33%;">
                                <el-select v-model="addData.email_getter_name" style="width: 100%;" filterable @change="handleSelectEmailGetter" :disabled="applyLogisticsDialogFormState==-2" @focus="handleGetEmailGetterByCustomerId()"  placeholder="请选择">
									<!--:label="(item.customer_name2==null?item.customer_name:item.customer_name2)+'('+item.email+')'"-->
                                    <el-option
                                            v-for="item in email_getter_array"
                                            :key="item.id"
                                            :label="(item.customer_name)+'('+item.email+')'"
                                            :value="item">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="邮箱" :label-width="formLabelWidth"  style="width:33%;">
                            <el-input v-model="addData.email_getter_email" :disabled="true" placeholder="暂无邮箱"></el-input>
                            </el-form-item>

                        </el-tab-pane>
                    </el-tabs>
                    <el-tabs type="card" v-model="tabscard">
                        <el-tab-pane label="物流信息" name="first">
                            <el-form-item label="物流服务商" prop="express_service" :label-width="formLabelWidth" class="add-long-input" style="width:33%;">
                                <el-select v-model="addData.express_service" filterable @change="handleChangeSupplier" style="width:70%" @focus="querySearchSupplier('')"  :disabled="applyLogisticsDialogFormState==-2" :filter-method="getrealService"  placeholder="请输入物流服务商">
                                    <el-option
                                            v-for="item in supplier_list"
                                            :key="item.id"
                                            :label="item.value"
                                            :value="item">
                                    </el-option>
                                </el-select>
                                <el-tooltip class="item" effect="dark" content="若系统中没有你所用的物流服务商，请先在服务商列表中添加服务商后再申请寄件" placement="top-start">
                                    <el-tag type="danger" style="margin-left: 20px;cursor: pointer;"><i class="el-icon-warning"></i>注意</el-tag>
                                </el-tooltip>
                            </el-form-item>
                            <el-form-item label="物流渠道" prop="express_company" :label-width="formLabelWidth" class="add-long-input" style="width:33%;">
                                <el-input v-model="addData.express_company" :disabled="applyLogisticsDialogFormState==-2"  ></el-input>
                            </el-form-item>
                            <el-form-item label="快递单号" prop="express_number" :label-width="formLabelWidth" class="add-long-input" style="width:33%;">
                                <el-input v-model="addData.express_number" :disabled="applyLogisticsDialogFormState==-2"  ></el-input>
                            </el-form-item>
                            <el-form-item label="快递费用" prop="real_price" :label-width="formLabelWidth" class="add-long-input" style="width:33%;">
                                <el-input v-model="addData.real_price" :disabled="applyLogisticsDialogFormState==-2"  ></el-input>
                            </el-form-item>
                        </el-tab-pane>
                    </el-tabs>
                    <el-tabs type="card" v-model="tabscard" style="position: relative;overflow: auto">
                        <el-tab-pane label="产品列表"  name="first" >
                            <el-table
                                    :data="addData.goods_data"
                                    border
                                    style="width: 100%">
                                    <el-table-column
                                        prop="goods_name"
                                        label="产品名称"
                                        align="center" header-align="center">
                                </el-table-column>
                                <el-table-column
                                        prop="english_name"
                                        label="英文名称" align="center" header-align="center">
                                </el-table-column>
                                <el-table-column
                                        prop="goods_number"
                                        label="产品数量"
                                        align="center" header-align="center"
                                >
                                </el-table-column>
                                <el-table-column
                                        prop="goods_price"
                                        label="单个产品申报价值"
                                        align="center" header-align="center">
                                </el-table-column>
                                <el-table-column
                                        prop="goods_unit_name"
                                        label="货币单位"
                                        align="center" header-align="center">
                                </el-table-column>
                                <el-table-column
                                        prop="goods_bianma"
                                        label="HS海关编码"
                                        align="center" header-align="center">
                                </el-table-column>
                                <el-table-column
                                        label="操作"
                                        align="center" header-align="center">
                                    <template slot-scope="scope">
                                        <el-button @click="delGoods(scope.row,scope.$index)" :disabled="applyLogisticsDialogFormState==-2 || applyLogisticsDialogFormState==-3" type="danger" size="small">删除
                                        </el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <div v-if="applyLogisticsDialogFormState!=-2 && applyLogisticsDialogFormState!=-3">
                                <el-form :model="new_goods_data" class="post_sample">
                                    <div style="display: flex; width:100%;margin-top:5px;">
                                        <div style="width:15%">
                                            <el-form-item label-width="0" style="width: 100%;">
                                                <el-input v-model="new_goods_data.goods_name" placeholder="中文产品名称" @blur="searchHsCode">
                                                </el-input>
                                            </el-form-item>
                                        </div>
                                        <div style="width:15%">
                                            <el-form-item label-width="0" style="width: 100%;">
                                                <el-input v-model="new_goods_data.english_name" placeholder="英文产品名称" >
                                                </el-input>
                                            </el-form-item>
                                        </div>
                                        <div style="width:15%">
                                            <el-form-item label-width="0" style="width: 100%;">
                                                <el-input  v-model="new_goods_data.goods_number" placeholder="产品数量">
                                                </el-input>
                                            </el-form-item>
                                        </div>
                                        <div style="width:30%">
                                            <el-form-item label-width="0" style="width: 100%;">
                                                <el-input placeholder="申报价格" v-model="new_goods_data.goods_price" class="input-with-select">
                                                    <template slot="prepend">{{goods_unit_list[new_goods_data.goods_unit]}}</template>
                                                    <el-select v-model="new_goods_data.goods_unit" style="width: 100px;" slot="append" placeholder="货币单位">
                                                        <el-option label="人民币" value="0"></el-option>
                                                        <el-option label="美元" value="1"></el-option>
                                                        <el-option label="欧元" value="2"></el-option>
                                                    </el-select>
                                                </el-input>
                                            </el-form-item>
                                        </div>
                                        <div style="width:15%">
                                            <el-form-item label-width="0" style="width: 100%;">
                                                <el-autocomplete
                                                        class="inline-input"
                                                        v-model="new_goods_data.goods_bianma"
                                                        :fetch-suggestions="querySearchHsCode"
                                                        placeholder="HS海关编码"
                                                        @select="handleSelectHsCode"
                                                        >
                                                </el-autocomplete>
                                            </el-form-item>
                                        </div>
                                        <div style="width:15%">
                                            <el-form-item label-width="0" style="width: 100%;">
                                                <el-button type="success" style="width: 50%;" size="small"  @click="addGoods()">添加</el-button>
                                            </el-form-item>
                                        </div>
                                    </div>
                                </el-form>
                            </div>
                    </el-tabs>
                </el-form>
                <div slot="footer">
                    <el-button @click="applyLogisticsDialogForm = false" v-if="applyLogisticsDialogFormState!==-2">取 消</el-button>
                    <el-button type="primary" @click="postLogisticsForm" :loading="addDataLoading" v-if="applyLogisticsDialogFormState!==-2">确 定</el-button>
                    <el-button type="primary"  v-if="applyLogisticsDialogFormState==-2" @click="applyLogisticsDialogForm=false">关 闭</el-button>
                </div>
            </el-dialog>

            <el-row class="search">
            <el-col :lg="4" :xl="5">
                收件人国家/地区：
                <el-select v-model="searchData.country" filterable @change="searchCountry" clearable @focus="remakeCountry" :filter-method="getrealCountry"    placeholder="请选择">
                    <el-option
                        v-for="item in searchCountryList"
                        :key="item.id"
                        :label="item.value"
                        :value="item">
                    </el-option>
                </el-select>
            </el-col>
            <el-col :lg="4" :xl="5">
                等待申请状态：
                <el-select v-model="searchData.status" placeholder="请选择" @change="search">
                    <el-option label="全部" value="-1"></el-option>
                    <el-option label="等待发货" value="0"></el-option>
                    <el-option label="发货完成" value="1"></el-option>
                    <el-option label="被驳回" value="2"></el-option>
                </el-select>
            </el-col>
            <el-col :span="4">
                客户名称：
                <el-select v-model="searchData.customer_name " clearable class="no-blue"  filterable @change="handleSelectCustomerForm" @focus="querySearchCustomer('',0)" :filter-method="getrealCustomer2"   placeholder="请选择">
                    <el-option
                        v-for="item in searchMoreCustomerList"
                        :key="item.id"
                        :label="item.customer_name"
                        :value="item">
                    </el-option>
                </el-select>
            </el-col>
            <el-col :span="4">
                客户编号：
                <el-input v-model="searchData.customer_code" placeholder="客户编号">
                </el-input>
            </el-col>
            </el-row>
            <el-row class="search">
                <el-col :span="4">
                    快递单号：
                    <el-input v-model="searchData.express_number" placeholder="快递单号">
                    </el-input>
                </el-col>
                <el-col :span="6">
                    日期：
                        <el-date-picker
                            style="position:relative;"
                            v-model="value1"
                            type="daterange"
                            @change='dateChange'
                            range-separator="-"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            :picker-options="pickerOptions"
                            :default-time="['00:00:00', '23:59:59']">
                        </el-date-picker>
                </el-col>
                <el-col :lg="4" :xl="5">
                物流服务商：
                <el-select v-model="LogisticsValue"   
                            remote filterable                           
                            @change="searchLogisticsChange" 
                            clearable  
                            @focus="remakeLogistics" 
                            :remote-method="remoteMethod"
                            placeholder="请输入">
                    <el-option
                        v-for="item in searchLogisticsProvidersList"
                        :key="item.id"
                        :label="item.value"
                        :value="item">
                    </el-option>
                </el-select>
            </el-col>
                <el-col :span="2">
                    <el-button type="primary" size="small" @click="search">搜索</el-button>
                </el-col>
            </el-row>
            <el-table :data="table_data">
                <el-table-column prop="report_number" label="寄件申请单号" width="140" align="center" header-align="center"></el-table-column>
                <el-table-column prop="customer_name" label="客户名称" width="140" align="center" header-align="center"></el-table-column>
                <el-table-column prop="status_name" label="寄件申请状态" width="100" align="center" header-align="center">
                    <template slot-scope="{row:{status_name,status,turn_back_reason}}">
                    <el-tag v-if="status!=2" :type="status_name.type">{{status_name.value}}</el-tag>
                        <el-popover
                        v-else
                        placement="top-start"
                        title="驳回理由"
                        width="300"
                        trigger="hover"
                        :content="turn_back_reason">
                        <el-tag slot="reference" :type="status_name.type">{{status_name.value}}</el-tag>
                        </el-popover>
                    </template>
                </el-table-column>
                <el-table-column prop="region_name" label="收件人国家/地区" width="140" align="center" header-align="center"></el-table-column>
                <el-table-column prop="express_service" label="物流服务商" width="150" align="center" header-align="center"></el-table-column>
                <el-table-column prop="express_company" label="物流公司" width="100" align="center" header-align="center"></el-table-column>
				<el-table-column prop="express_number" label="运单号" width="150" align="center" header-align="center"></el-table-column>
                <el-table-column prop="press_weight" label="计重" width="100" align="center" header-align="center"></el-table-column>
                <el-table-column prop="real_price" label="实际费用" width="130" align="center" header-align="center"></el-table-column>
                <el-table-column prop="finish_time" label="发货完成时间" width="150" align="center" header-align="center"></el-table-column>
                <el-table-column prop="creator" label="业务员" width="80" align="center" header-align="center"></el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button
                                size="mini"
                                @click="handleEdit(scope.$index, scope.row , -2)">查看
                        </el-button>
                        <el-button v-if="(scope.row.status == 0 || scope.row.status == 2)&& (scope.row.creator_job_number==job_number || isDocuments)"
                                size="mini" type="primary"
                                @click="handleEdit(scope.$index, scope.row , 1)">编辑
                        </el-button>
                        <el-button v-if="scope.row.status == 0 && isDocuments"
                                size="mini" type="success"
                                @click="handleEdit(scope.$index, scope.row , 2)">发货/发送邮件
                        </el-button>
                        <el-button v-if="scope.row.status == 0 && isDocuments"
                                size="mini" type="danger"
                                @click="handleEdit(scope.$index, scope.row , 4)">驳回
                        </el-button>
                        <el-button v-if="scope.row.status == 2 && scope.row.creator_job_number==job_number"
                                size="mini" type="danger"
                                @click="handelDeleteSample(scope.row.id)">删除
                        </el-button>
                        <el-button v-if="scope.row.status == 1 && scope.row.creator_job_number==job_number"
                                   size="mini"
                                   type="success"
                                   @click="handleEdit(scope.$index, scope.row , 3)">再来一单
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="page"
              :page-sizes="[10, 20, 50, 100]"
              :page-size="10"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
            </el-pagination>
            <el-dialog title="补充物流信息" :visible.sync="editData.is_show" @closed="handelCloseEdit">
                <el-form :model="editData" ref="edit_form" :rules="editData.rules" class="post_sample">
                    <el-form-item label="物流服务商" prop='express_service' :label-width="formLabelWidth">
                        <el-select v-model="editData.express_service" filterable @change="handleEditSupplierChange" style="width:70%" @focus="querySearchSupplier('')" placeholder="请输入物流服务商" :filter-method="getrealService">
                            <el-option
                                    v-for="item in supplier_list"
                                    :key="item.id"
                                    :label="item.value"
                                    :value="item">
                            </el-option>
                        </el-select>
                        <el-tooltip class="item" effect="dark" content="若系统中没有你所用的物流服务商，请先在服务商列表中添加服务商后再申请寄件" placement="top-start">
                            <el-tag type="danger" style="margin-left: 20px;cursor: pointer;"><i class="el-icon-warning"></i>注意</el-tag>
                        </el-tooltip>
                    </el-form-item>
                    <el-form-item label="物流渠道" prop='express_company' :label-width="formLabelWidth">
                        <el-input v-model="editData.express_company" ></el-input>
                    </el-form-item>
                    <el-form-item label="快递单号" prop='express_number' :label-width="formLabelWidth">
                        <el-input v-model="editData.express_number" ></el-input>
                    </el-form-item>
                    <el-form-item label="快递费用" prop='real_price' :label-width="formLabelWidth">
                        <el-input v-model="editData.real_price" ></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer">
                    <el-button @click="editData.is_show = false">取 消</el-button>
                    <el-button type="primary" :disabled="editData.dis_click" @click="dialogFormConsignmentPost">确 定</el-button>
                </div>
            </el-dialog>
            <el-dialog title="驳回申请" :visible.sync="turn_down_form.show" @close="handelCloseTurnDown" :close-on-click-modal="false" :destroy-on-close="true" style="width:30%; margin:0 auto;margin-top:10%;">
                <el-form :model="turn_down_form.data" ref="turn_down_form" :rules="turn_down_form.rules"  label-width="80px" :inline="false">
                    <el-form-item label="驳回理由" prop='reason'>
                        <el-input v-model="turn_down_form.data.reason" type="textarea" :rows="2" :maxlength="80" :show-word-limit="true" placeholder="请输入驳回理由理由"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer">
                    <el-button @click="turn_down_form.show = false">取 消</el-button>
                    <el-button type="primary" :disabled="turn_down_form.loading" @click="handelTurnDownSample">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>

    <script>
        var first_in=0;
        new Vue({
            el: '#app',
            computed: {
                //判断是否有权限
                isDocuments() {
                    return this.documents.some((item) => this.job_number == item)
                },
		    },
            watch : {
                'addData.long' : {
                    handler(val) {
                        val=testInputNumber(val);
                        if(parseInt(val)>99999){
                            val=99999
                        }
                        if(val != '') {
                            this.addData.long = parseInt(val)
                        }else {
                            this.addData.long=''
                        }
                        this.computeWeight()
                    },
                    deep : true
                },
                'addData.width' : {
                    handler(val) {
                        val=testInputNumber(val);
                        if(parseInt(val)>99999){
                            val=99999
                        }
                        if(val != '') {
                            this.addData.width = parseInt(val)

                        }else {
                            this.addData.width=''
                        }
                        this.computeWeight();
                    },
                    deep : true
                },
                'addData.height' : {
                    handler(val) {
                        val=testInputNumber(val);
                        if(parseInt(val)>99999){
                            val=99999
                        }
                        if(val != '') {
                            this.addData.height = parseInt(val)

                        }else {
                            this.addData.height=''
                        }
                        this.computeWeight();
                    },
                    deep : true
                },
                'addData.weight':{
                    handler(val) {
                        if(parseInt(val)>99999){
                            this.addData.weight=99999
                        }
                    },
                    deep : true
                },
                'addData.press_weight':{
                    handler(val) {
                        if(parseInt(val)>99999){
                            this.addData.press_weight=99999
                        }
                    },
                    deep : true
                },
                'addData.real_weight' : {
                    handler(val) {
                        val=testFloatNumber(val,2);
                        if(parseInt(val)>99999){
                            val=99999
                        }
                        if(val != '') {
                            this.addData.real_weight = val;
                        }else {
                            this.addData.real_weight=''
                        }
                        this.computeWeight();
                    },
                    deep : true
                },
                'addData.post_code':{
                    handler(val) {
                         val=testInputNumberAndA_z(val)
                         this.addData.post_code=val
                    },
                    deep : true
                },
                'addData.press_tel':{
                    handler(val) {
                        val=testInputNumber(val)
                        this.addData.press_tel=val
                    },
                    deep : true
                },
                'new_goods_data.goods_number':{
                    handler(val) {
                        val=testInputNumber(val)
                        this.new_goods_data.goods_number=val
                    },
                    deep : true
                },
                'new_goods_data.goods_bianma':{
                    handler(val) {
                        val=testFloatNumber(val,2);
                        this.new_goods_data.goods_bianma=val
                    },
                    deep : true
                },
                'new_goods_data.goods_price':{
                    handler(val) {
                        val=testFloatNumber(val,2);
                        this.new_goods_data.goods_price=val
                    },
                    deep : true
                },
                'addData.real_price':{
                    handler(val) {
                        val=testFloatNumber(val,2);
                        this.addData.real_price=val
                    },
                    deep : true
                },
                'addData.express_number':{
                    handler(val) {
                        val=testInputNumberAndA_z(val);
                        this.addData.express_number=val
                    },
                    deep : true
                },
                'editData.real_price':{
                    handler(val) {
                        val=testFloatNumber(val,2);
                        this.addData.real_price=val
                    },
                    deep : true
                },
                'editData.express_number':{
                    handler(val) {
                        val=testInputNumberAndA_z(val);
                        this.addData.express_number=val
                    },
                    deep : true
                }
            },
            data() {
                return {
                    documents:<?php echo json_encode(Yii::$app->params['logistics_master']['sample']); ?>,
                    hscodelist : [],
                    tabscard : 'first',
                    job_number:<?php echo $job_number;?>,
                    isSaleMan:<?php echo in_array($role, $temp_permition_limit) ? 'true' : 'false'; ?>,
                    role:<?php echo $role;?>,
                    editLogisticsButton : true,
                    applyLogisticsDialogEditGoodsForm : false,
                    applyLogisticsDialogForm: false,
                    new_goods_data : {
                        goods_name : '',
                        english_name:'',
                        goods_number : '',
                        goods_price : '',
                        goods_bianma : '',
                        goods_unit : ''
                    },
                    customer_list: [],
                    formLabelWidth: '98px',
                    searchData: {
                        status: '-1',
                        customer_id: '',
                        customer_name : '',
                        country_id:'',
                        country:{},
                        customer_code:'',
                        express_number:'',     
                        begin_time:'',
                        end_time:'',     
                        express_company_id:"",                
                    },
                    value1: '',
                    LogisticsValue:'',
                    pickerOptions: {
                            shortcuts: [
                                {
                                    text:'今天',
                                    onClick(picker){
                                        let end = new Date();                      
                                        let start=new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        picker.$emit('pick',[start,end]);
                                    }
                                },
                                {
                                    text: '3天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start = new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 3);
                                        end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '本周',
                                    onClick(picker) {
                                        var nowTemp = new Date(new Date(new Date().toLocaleDateString()).getTime())//当天的0点0分0秒
                                        cTime = nowTemp.getTime(); //当前时间的毫秒时间
                                        cDay = nowTemp.getDay() || 7; //当前时间的星期几
                                        mTime = cTime - (cDay - 1) * 24 * 60 * 60 * 1000; //当前周一的毫秒时间
                                        monday = new Date(mTime); //设置周一时间对象
                                        const end = new Date();
                                        const start = monday;
                                        picker.$emit('pick', [start, end]);                                    
                                    }
                                }
                                , {
                                    text: '上周',
                                    onClick(picker) {
                                        var nowTemp = new Date(new Date(new Date().toLocaleDateString()).getTime())//当天的0点0分0秒
                                        let lastTime =new Date(new Date(new Date().toLocaleDateString()).getTime()+24*60*60*1000-1)//当天的最后一秒
                                        cTime = nowTemp.getTime(); //当前0点的毫秒时间
                                        lTime = lastTime.getTime();//当前59秒的毫秒时间
                                        cDay = nowTemp.getDay() || 7; //当前时间的星期几
                                        mTime2 = lTime - (cDay - 1) * 24 * 60 * 60 * 1000 - 24 * 3600 * 1000; //当前周一的毫秒时间结束时间
                                        mTime1 = cTime - (cDay - 1) * 24 * 60 * 60 * 1000 - 7 * 24 * 60 * 60 * 1000; //上周一的毫秒时间
                                        let end = new Date(mTime2);
                                        let start = new Date(mTime1);
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '本月',
                                    onClick(picker) {
                                        var data=new Date(new Date(new Date().toLocaleDateString()).getTime())//当天的0点0分0秒
                                        data.setDate(1);
                                        data.setHours(0);
                                        data.setSeconds(0);
                                        data.setMinutes(0);
                                        const end = new Date();
                                        const start = data;
                                        end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '上月',
                                    onClick(picker) {
                                        var data=new Date();
                                        data.setDate(1);
                                        data.setHours(0);
                                        data.setSeconds(0);
                                        data.setMinutes(0);
                                        data.setMonth(data.getMonth() - 1);
                                        var data2 = new Date();
                                        data2.setDate(1);
                                        data2.setHours(0);
                                        data2.setSeconds(0);
                                        data2.setMinutes(0);
                                        const end = data2;
                                        const start = data;
                                        end.setTime(end.getTime()-1000);
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '7天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start =new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                        end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                     
                                    }
                                }
                                , {
                                    text: '14天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start = new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 14);
                                      end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '30天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start =new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                         end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '60天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start =new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 60);
                                        end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '90天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start =new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                        end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }
                                , {
                                    text: '120天',
                                    onClick(picker) {
                                        const end = new Date();
                                        const start =new Date(new Date(new Date().toLocaleDateString()).getTime())
                                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 120);
                                        end.setTime(end.getTime());
                                        picker.$emit('pick', [start, end]);
                                    }
                                }]
                    },
                    goods_unit_list:[
                        '¥','$','€'
                    ],
                    status_list:[
                        {value:'等待发货',type:''},
                        {value:'发货完成',type:'success'},
                        {value:'被驳回',type:'danger'},
                    ],
                    addDataLoading: false,
                    editData:{
                        id:'',
                        express_service:'',
                        express_company:'',
                        express_company_id:'',
                        supplier_id:'',
                        express_number:'',
                        real_price:'',
                        rules: {
                            express_service: [
                                {required: true, message: '物流服务商必填', trigger: 'blur' }
                            ],
                            express_company: [
                                { required: true, message: '物流渠道必填', trigger: 'blur' }
                            ],
                            express_number: [
                                { required: true, message: '物流单号必填', trigger: 'blur' }
                            ],
                            real_price: [
                                { required: true, message: '实际费用必填', trigger: 'blur' }
                            ]
                        },
                        is_show:false,
                        dis_click:false
                    },
                    addData: {
                        op_type:0,
                        id : 0,
                        express_company: '',
                        supplier_id:'',
                        express_company_id:'',
                        real_price:'',
                        express_service:'',
                        express_number:'',
                        long: '',
                        width: '',
                        height: '',
                        weight: '',
                        real_weight: '',
                        press_weight: '',
                        country:'',
                        numberCode:'',
                        customer_id : '',
                        customer_name: '',
                        customer_number: '',
                        press_name: '',
                        press_tel: '',
                        region_name : '',
                        country_id: '',
                        province_name : '',
                        city_name : '',
                        press_addr: '',
                        post_code : '',
                        goods_data: [],
                        comment:'',
                        email_getter_name:'',
                        email_getter:'',
                        email_getter_email:'',
                        rules: {
                            long: [
                                {required: true, message: '长度必填', trigger: 'blur' }
                            ],
                            width: [
                                { required: true, message: '宽度必填', trigger: 'blur' }
                            ],
                            height: [
                                { required: true, message: '高度必填', trigger: 'blur' }
                            ],
                            real_weight: [
                                { required: true, message: '实际重量必填', trigger: 'blur' }
                            ],
                            customer_name: [
                                {required: true, message: '客户名称必填', trigger: 'blur' }
                            ],
                            customer_number: [
                                { required: true, message: '客户编号必填', trigger: 'blur' }
                            ],
                            press_name: [
                                { required: true, message: '收件人姓名必填', trigger: 'blur' }
                            ],
                            region_name: [
                                { required: true, message: '收件人国家必填', trigger: 'blur' }
                            ],
                            province_name: [
                                {required: true, message: '省份/州必填', trigger: 'blur' }
                            ],
                            city_name: [
                                { required: true, message: '城市必填', trigger: 'blur' }
                            ],
                            press_tel: [
                                { required: true, message: '收件人电话必填', trigger: 'blur' }
                            ],
                            press_addr: [
                                { required: true, message: '实际地址必填', trigger: 'blur' }
                            ],
                            post_code: [
                                { required: true, message: '邮编必填', trigger: 'blur' }
                            ],
                            email_getter_name: [
                                { required: true, message: '寄件邮件收入人必填', trigger: 'blur' }
                            ],
                        }
                    },
                    table_data: [],
                    page : 1,
                    limit : 10,
                    total : 0,
                    rules : {
                        country_id : [
                            ['empty','请选择顾客所在的国家/地区'],
                            ['lte',0,'']
                        ],
                        customer_name : [
                            ['empty','客户名称不能为空']
                        ],
                        customer_id : [
                            ['empty','未选择正确客户']
                        ],
                        customer_number : [
                            ['empty','未选择正确客户02']
                        ],
                        press_name : [
                            ['empty','收件人姓名不能为空']
                        ],
                        press_tel : [
                            ['empty','收件人电话不能为空']
                        ],
                        province_name : [
                            ['empty','请填写收件人地址所在的州/省份']
                        ],
                        city_name : [
                            ['empty','请填写收件人地址所在的城市']
                        ],
                        press_addr : [
                            ['empty','填写收件人的详细地址']
                        ],
                        post_code : [
                            ['empty','请填写收件人所在城市的邮编']
                        ],
                        goods_data : [
                            ['empty_array','请增加相应的产品']
                        ],
                        real_weight:[
                            ['empty','请填写货物实重']
                        ],
                        email_getter:[
                            ['empty','请选择发货邮件收取人']
                        ]
                    },
                    allCountryList:[],
                    searchCountryList:[],
                    searchCustomerList:[],
                    searchMoreCustomerList:[],
                    searchLogisticsProvidersList:[],
                    /*控制弹窗*/
                    applyLogisticsDialogFormState:0,
                    timer:null,
                    email_getter_array:{},
                    supplier_list:[],
                    turn_down_form:{
                        data:{
                            id:0,
                            reason:''
                        },
                        show:false,
                        loading:false,
                        rules:{
                            reason: [{
                                required: true,
                                message: "不可为空",
                                trigger: "blur",
                            }, ]
					    }
                    }
                }
            },
            mounted(){
                this.getALlCountry();
                /*监听防抖*/
                this.computeWeight = debounce(this.computeWeight.bind(this), 300)
                this.querySearchCustomer=debounce(this.querySearchCustomer.bind(this), 300)
                this.querySearchSupplier=debounce(this.querySearchSupplier.bind(this), 300)
            },
            methods: {
                //日期输入框改变时
                dateChange(e){
                    if(e==null){
                        this.value1=[]
                        this.searchData.begin_time=null
                        this.searchData.end_time=null
                    }else{
                        this.searchData.begin_time=this.dateToMs(this.value1[0])
                        this.searchData.end_time=this.dateToMs(this.value1[1])
                    }          
                },
                //改为时间戳格式10位
                dateToMs(date) {
                    let result =Math.trunc(new Date(date).getTime()/1000)
                    return result;
                },
                handelDeleteSample(id){
                    this.$confirm('是否删除该寄件申请', '提示', {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        axios.post('/api/logistics/delete-sample-logistics',{
                            id
                        }).then(response=> {
                                if(response.data.code == 0) {
                                    this.$message({
                                        type: 'success',
                                        message: '删除成功'
                                    });
                                    this.loadData();

                                }else{
                                    this.$message({
                                        type: 'error',
                                        message: response.data.msg
                                    });
                                    this.loadData();
                                }
                            })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消'
                        });
                    });
                },
                //驳回申请弹窗关闭回调
                handelCloseTurnDown(){
                    this.turn_down_form=this.$options.data().turn_down_form;
                },
                //编辑/新增弹窗开启时回调
                applyDialogFormOpen(){
                    this.getALlCountry();
                },
                //新增弹窗关闭时的回调
                applyDialogFormClose(){
                   this.applyLogisticsDialogFormState=0
                   this.reMakeData()
                },
                /*json搜索国家*/
                getrealCountry(val){
                    if (val) { //val存在
                        this.searchCountryList = this.allCountryList.filter((item) => {
                            //首字母查询
                            val=val.replace(/\s*/g,"")
                            if(val.toLowerCase()==item.value.substr(0,val.length).replace(/\s*/g,"").toLowerCase()){
                                return true
                            }
                        })
                    } else { //val为空时，还原数组
                        this.remakeCountry()
                    }
                },
                 /*json搜索物流服务商*/
                 remoteMethod(val){
                    axios.get('/ware/get-logistics-service',{params:{name:val}}).then(res=> {
                                this.searchLogisticsProvidersList=res.data.data.list
                            }).catch(()=>{                
                            })
                },
                /** 通过关键字模糊查询物流供应商 */
                querySearchSupplier(name){
                    if(name==""){
                        name=null
                    }
                    http.get("/ware/get-logistics-service", { params: {
                        name
                    } })
                        .then((res) => {
                            // handle success
                        let list = [];
                        if(res.code==0){
                            this.supplier_list=res.data.list
                        }else{
                            this.$message({
                                type: 'error',
                                message: res.data.msg
                            });
                        }
                        })
                        .catch(() => {

                        });
                },
                /** 校验寄件数据是否完整，是否可以发邮件*/
                checkCanEmail(id) {
                    return http.get("/logistics/check-is-complete", { params: { id } })
                },
                // 清空数据
                handelCloseEdit(){
                    this.editData.id=''
                    this.editData.express_service=''
                    this.editData.express_company=''
                    this.editData.supplier_id=''
                    this.editData.express_company_id=''
                    this.editData.express_number=''
                    this.editData.real_price=''
                },
                //开启编辑物流信息
                handelOpenEdit(id){
                    var data=this.addData
                    this.editData.id=id;
                    this.editData.express_service=data.express_service
                    this.editData.express_company=data.express_company
                    this.editData.supplier_id=data.supplier_id
                    this.editData.express_company_id=data.express_company_id
                    this.editData.express_number=data.express_number
                    this.editData.real_price=data.real_price
                    this.editData.is_show=true
                    //初始化数据
                },
                //提交物流信息
                dialogFormConsignmentPost(){
                    this.$refs['edit_form'].validate((valid) => {
                        if (valid) {
                            this.editData.dis_click=true;
                            let data ={
                               id:this.editData.id,
                               express_service:this.editData.express_service,
                               supplier_id:this.editData.supplier_id,
                               express_company_id:this.editData.express_company_id,
                               express_company:this.editData.express_company,
                               express_number:this.editData.express_number,
                               real_price:this.editData.real_price
                            }
                            axios.post('/api/logistics/edit-sample',data).then(res=> {
                                this.editData.is_show = false;
                                if(res.data.code == 0) {
                                    this.$message({
                                        type: 'success',
                                        message: res.data.msg
                                    })
                                    this.emailGoods(data.id);
                                }else{
                                    this.$message({
                                    type: 'error',
                                    message: res.data.msg
                                    });
                                }

                                this.editData.dis_click=false;
                            }).catch(()=>{
                                this.editData.dis_click=false;
                            })
                        } else {
                            return false;
                        }
                    });
                },
                /** 选择供应商 */
                handleChangeSupplier(item){
                    this.addData.express_service = item.value;
                    this.addData.supplier_id=item.supplier_id
                    this.addData.express_company_id=item.express_company_id
                },
                //编辑供应商
                handleEditSupplierChange(item){
                    this.editData.express_service = item.value;
                    this.editData.supplier_id=item.supplier_id
                    this.editData.express_company_id=item.express_company_id
                },
                remakeCountry(){
                    this.searchCountryList=this.allCountryList
                },
                 //物流服务商获取焦点事件
                remakeLogistics(){
                     axios.get('/ware/get-logistics-service',{params:{}}).then(res=> {
                                this.searchLogisticsProvidersList=res.data.data.list
                            }).catch(()=>{                
                            })
                },
                //物流服务商change事件
                searchLogisticsChange(e){           
                    this.searchData.express_company_id=e.express_company_id
                },
                //json搜索用户
                getrealCustomer(val){
                    if (val) { //val存在
                        this.querySearchCustomer(val,1)
                    } else { //val为空时，还原数组
                        this.querySearchCustomer('',1)
                    }
                },
                //json搜索物流服务商
                getrealService(val){
                    if (val) { //val存在
                        this.querySearchSupplier(val)
                    } else { //val为空时，还原数组
                        this.querySearchSupplier('')
                    }
                },
                //json搜索用户
                getrealCustomer2(val){
                    if (val) { //val存在
                        this.querySearchCustomer(val,0)
                    } else { //val为空时，还原数组
                        this.querySearchCustomer('',0)
                    }
                },
                remakeCustomer(){
                    this.searchCustomerList=this.allCustomerList
                },
                remakeCustomer2(){
                    this.searchMoreCustomerList=this.allMoreCustomerList
                },
                searchHsCode() {
                    axios.get('/api/logistics/searchcode',{
                        params : {
                            goods_name : this.new_goods_data.goods_name
                        }
                    }).then(response=>{
                        this.hscodelist = response.data;
                    })
                },
                postData() {
                    this.reMakeData();
                    this.applyLogisticsDialogForm = true
                },
                //重置页面数据
                reMakeData(){
                    this.addData.id = 0;
                    this.addData.op_type=0;
                    this.addData.express_company = '';
                    this.addData.supplier_id='';
                    this.addData.express_company_id='';
                    this.addData.long = '';
                    this.addData.width = '';
                    this.addData.height = '';
                    this.addData.weight = '';
                    this.addData.real_weight = '';
                    this.addData.press_weight = '';
                    this.addData.customer_id = '';
                    this.addData.customer_name = '';
                    this.addData.customer_number = '';
                    this.addData.press_name = '';
                    this.addData.press_tel = '';
                    this.addData.region_name = '';
                    this.addData.country_id = '';
                    this.addData.province_name = '';
                    this.addData.numberCode='';
                    this.addData.city_name = '';
                    this.addData.press_addr = '';
                    this.addData.post_code = '';
                    this.addData.goods_data = [];
                    this.addData.comment=''
                    this.addData.country=''
                    this.addData.email_getter_name=''
                    this.addData.email_getter=''
                    this.addData.email_getter_email=''
                    this.addData.real_price=''
                    this.addData.express_service=''
                    this.addData.express_number=''
                    this.addData.data_snapshot=''
                    this.email_getter_array=[]
                    this.new_goods_data={
                        goods_name : '',
                        goods_number : '',
                        english_name:'',
                        goods_price : '',
                        goods_bianma : '',
                        goods_unit : '',
                        goods_unit_name:''
                    }
                },
                handleSizeChange(v){
                    this.limit = v;
                    this.loadData();
                },
                handleCurrentChange(v){
                    this.page = v;
                    this.loadData();
                },
                handleEdit(i , dd , status) {
                    let d = dd;
                    switch(status) {
                        case 1: //编辑
                            for(let key  in d){
                                if(key=='long'||key=='width'||key=='height'){
                                    this.addData[key] = parseInt(d[key])
                                }else {
                                    this.addData[key] = d[key];
                                }
                            }
                            if(this.addData.email_getter!=''){
                                this.get_email_getter(this.addData.email_getter)
                                .then((res) => {
                                    this.addData.email_getter_email=res.data.email
                                })
                                .catch((err) =>{})
                            }
                            this.addData.op_type=1
                            if(this.isDocuments){
                                //单证编辑
                                this.applyLogisticsDialogFormState=-3
                            }
                            this.applyLogisticsDialogForm = true;
                            break;
                        case 3: //再来一单
                            for(let key  in d){
                                if(key=='long'||key=='width'||key=='height'){
                                    this.addData[key] = parseInt(d[key])
                                }else {
                                    this.addData[key] = d[key];
                                }
                            }
                            if(this.addData.email_getter!=''){
                                this.get_email_getter(this.addData.email_getter)
                                .then((res) => {
                                    this.addData.email_getter_email=res.data.email
                                })
                                .catch((err) =>{})
                            }
                            this.addData.express_number=""
                            this.addData.real_price=""
                            this.addData.op_type=0
                            this.applyLogisticsDialogForm = true;
                            break;
                        case -2: //查看
                            for(let key  in d){
                                if(key=='long'||key=='width'||key=='height'){
                                    this.addData[key] = parseInt(d[key])
                                }else {
                                    this.addData[key] = d[key];
                                }
                            }
                            if(this.addData.status!=1 && this.addData.email_getter!=''){
                                this.get_email_getter(this.addData.email_getter)
                                .then((res) => {
                                    this.addData.email_getter_email=res.data.email
                                    // this.addData.email_getter_name=(res.data.customer_name2==null?res.data.customer_name:res.data.customer_name2)
                                    this.addData.email_getter_name=(res.data.customer_name)
                                })
                                .catch((err) =>{})
                            }
                            if(this.addData.status==1 && this.addData.data_snapshot!==null){
                                this.addData.customer_name=this.addData.data_snapshot.customer_info.customer_name,
                                this.addData.customer_number = this.addData.data_snapshot.customer_info.number;
                                this.addData.customer_id = this.addData.data_snapshot.customer_info.id;
                                this.addData.email_getter_email=this.addData.data_snapshot.email_getter_info.email
                                // this.addData.email_getter_name=(this.addData.data_snapshot.email_getter_info.customer_name2==null?this.addData.data_snapshot.email_getter_info.customer_name:this.addData.data_snapshot.email_getter_info.customer_name2)
                                this.addData.email_getter_name=(this.addData.data_snapshot.email_getter_info.customer_name)
                                this.addData.email_getter=this.addData.data_snapshot.email_getter_info.id
                            }
                            this.editLogisticsButton = false;
                            this.applyLogisticsDialogForm = true;
                            this.applyLogisticsDialogFormState=-2
                            break;
                            case 2: //发货/发邮件
                            for(let key  in d){
                                if(key=='long'||key=='width'||key=='height'){
                                    this.addData[key] = parseInt(d[key])
                                }else {
                                    this.addData[key] = d[key];
                                }
                            }
                            this.checkCanEmail(this.addData.id)
                            .then(res=>{
                                if(res.code==0){
                                    //发起寄件
                                    this.emailGoods(this.addData.id)
                                }
                            }).catch(res=>{
                                let msg=res.data.msg;
                                //填写数据
                                if(msg=="物流信息不完整"){
                                    this.handelOpenEdit(this.addData.id)
                                }else if(msg=="寄件地区不明确"){
                                    this.addData.op_type=1
                                    this.applyLogisticsDialogForm = true;
                                }
                            })
                            break;
                            case 4:
                                this.turn_down_form.data.id=d.id
                                this.turn_down_form.show=true
                            break;
                        default:
                            this.$message({
                                type: 'error',
                                message: '未确定的操作方式'
                            });
                            break;
                    }
                },
                handelTurnDownSample(){
                    this.$refs["turn_down_form"].validate((valid) => {
                	if (!valid) return false;
                    this.turn_down_form.loading=true
                        let data = {
                                id:this.turn_down_form.data.id,
                                reason:this.turn_down_form.data.reason
                            }
                        axios.post('/api/logistics/turn-down-sample',data).then(res=> {
                            if(res.data.code == 0) {
                                this.$message({
                                    type: 'success',
                                    message: res.data.msg
                                })
                                this.turn_down_form.show=false
                                this.loadData()
                            }else{
                                this.$message({
                                type: 'error',
                                message: res.data.msg
                                });
                                this.turn_down_form.loading=false
                            }
                            }).catch(()=>{
                                this.turn_down_form.loading=false
                            })
           		    });
                },
                //发起寄件
                emailGoods(id){
                    this.$confirm('是否确认发货并且发送邮件给客户?', '请确认', {
                                confirmButtonText: '确认发送',
                                cancelButtonText: '取消发送',
                                type: 'success'
                            }).then(() => {
                                let data = {
                                    id
                                }
                                axios.post('/api/logistics/confirm-and-email',data).then(res=> {
                                if(res.data.code == 0) {
                                    this.$message({
                                        type: 'success',
                                        message: res.data.msg
                                    })
                                    this.loadData()
                                }else{
                                    this.$message({
                                    type: 'error',
                                    message: res.data.msg
                                    });
                                }
                                }).catch(()=>{
                                })
                            }).catch(() => {
                                this.$message({
                                    type: 'info',
                                    message: '已取消'
                                });
                                this.loadData()
                            });
                },
                search() {
                    this.loadData(1);
                },
                loadData(page) {
                    let data_page = this.page;
                    if(page != undefined) {
                        data_page = page;
                    }
                    let search=this.searchData;
                    let params={}
                    params.page = data_page;
                    params.limit = this.limit;
                    params.country_id=search.country_id==''?null:search.country_id
                    params.customer_code=search.customer_code==''?null:search.customer_code
                    params.status=search.status==-1?null:search.status
                    params.customer_id=search.customer_id==''?null:search.customer_id
                    params.express_number=search.express_number==''?null:search.express_number
                    params.begin_time=search.begin_time==''?null:search.begin_time
                    params.end_time=search.end_time==''?null:search.end_time
                    params.express_company_id= search.express_company_id==''?null:search.express_company_id
                    axios.get('/api/logistics/sample-list', {
                        params : params
                    }).then(response=> {
                        if(response.data.code==0){
                            this.table_data = response.data.data.list;
                            this.table_data.forEach(ite=>{
                                ite.status_name=this.status_list[ite.status]
                                let country_id=ite.country_id
                            try {
                                this.allCountryList.forEach(item => {
                                    if (item.id == country_id) {
                                        ite.numberCode=item.code
                                        ite.region_name=item.value
                                            //跳出循环
                                        throw new Error("ending")
                                    }
                                })
                            } catch (e) {
                                    if (e.message == "ending") {}
                                }
                            ite.goods_data.forEach(item => {
                                item.goods_unit_name=this.goods_unit_list[item.goods_unit]
                            });
                                })
                            this.total = parseInt(response.data.data.total);
                        }else{
                            this.$message({
                            type: 'error',
                            message: response.data.msg
                            });
                        }
                    }).catch(error=> {
                    })
                    .then(()=>{
                        // always executed
                    });
                },
                checkFields(rules,params) {
                    let resObj = {
                        status : true,
                        msg : ''
                    };
                    Object.keys(rules).forEach(key => {
                        rules[key].map(item => {
                            if(resObj.status == true) {
                                switch(item[0]) {
                                    case 'empty':
                                        if(params[key] == ''){
                                            resObj.status = false;
                                            resObj.msg = item[1];
                                        }
                                        break;
                                    case 'number' :
                                        let r = /^[0-9]+.?[0-9]*/;
                                        if(!r.test(item[0])) {
                                            resObj.status = false;
                                            resObj.msg = item[1];
                                        }
                                        break;
                                    case 'empty_array':
                                        if(params[key].length == 0) {
                                            resObj.status = false;
                                            resObj.msg = item[1];
                                        }
                                        break;
                                    case 'lte': // <=
                                        if(params[key] <= item[1]) {
                                            resObj.status = false;
                                            resObj.msg = item[2];
                                        }
                                        break;
                                    case 'lt': // <
                                        if(params[key] < item[1]) {
                                            resObj.status = false;
                                            resObj.msg = item[2];
                                        }
                                        break;
                                    case 'gt': // >
                                        if(params[key] > item[1]) {
                                            resObj.status = false;
                                            resObj.msg = item[2];
                                        }
                                        break;
                                    case 'gte': // >=
                                        if(params[key] >= item[1]) {
                                            resObj.status = false;
                                            resObj.msg = item[2];
                                        }
                                        break;
                                    default:
                                        break;
                                }
                            }

                        });
                    });
                    return resObj;
                },
                //提交寄件钱申请
                postLogisticsForm() {
                    let checkRules = this.checkFields(this.rules,this.addData);
                    if(this.addData.width == '' || this.addData.height == '' || this.addData.long == '') {
                        this.$message({
                            type: 'error',
                            message: '必填入包装的长、宽、高'
                        });
                        return false;
                    }
                    if(checkRules.status == false){
                        this.$message({
                            type: 'error',
                            message: checkRules.msg
                        });
                        return false;
                    }
                    let data=this.addData
                    data.goods_data.forEach(item=>{
                        delete item.goods_unit_name
                    })
                    let postData={
                        op_type:data.op_type,
                        id:data.id,
                        express_company:data.express_company,
                        supplier_id:data.supplier_id,
                        express_company_id:data.express_company_id,
                        express_number:data.express_number,
                        express_service:data.express_service,
                        real_price:data.real_price,
                        long:data.long,
                        width:data.width,
                        height:data.height,
                        weight:data.weight,
                        real_weight:data.real_weight,
                        press_weight:data.press_weight,
                        customer_id:data.customer_id,
                        press_name:data.press_name,
                        press_tel:data.press_tel,
                        country_id:data.country_id,
                        province_name:data.province_name,
                        city_name:data.city_name,
                        press_addr:data.press_addr,
                        post_code:data.post_code,
                        goods_data:data.goods_data,
                        comment:data.comment,
                        email_getter:data.email_getter
                    }
                    this.addDataLoading = !this.addDataLoading;
                    axios.post('/api/logistics/add-sample',postData).then(response=> {
                        if(response.data.code == 0) {
                            this.applyLogisticsDialogForm = false;
                            this.$message({
                              message: '申请已提交,确认无误后可自行发货并发送邮件',
                              center: true,
                              type:'success'
                            });
                            this.loadData();
                        }else{
                            this.$message({
                              message: response.data.msg,
                              center: true,
                              type:'warning'
                            });
                        }
                        this.addDataLoading = !this.addDataLoading;
                    }).catch(() =>{
                        this.addDataLoading = !this.addDataLoading;
                    })
                },
                addGoods() {
                    let checkRules = this.checkFields({
                        goods_name : [
                            ['empty','商品名称不能为空']
                        ],
                        goods_number : [
                            ['empty','请输入产品数量']
                        ],
                        goods_price : [
                            ['empty','请输入产品的申报价格']
                        ],
                        goods_bianma : [
                            ['empty','请填写海关编码']
                        ],
                        goods_unit : [
                            ['empty','请选择价格的单位']
                        ],
                        english_name:[
                            ['empty','产品英文名称不能为空']
                        ]
                    },this.new_goods_data);
                    if(checkRules.status == false){
                        this.$message({
                            type: 'error',
                            message: checkRules.msg
                        });
                        return false;
                    }
                    // this.new_goods_data.ikey = Math.random();
                    let addGood=this.new_goods_data
                    addGood.goods_unit_name=this.goods_unit_list[addGood.goods_unit]
                    this.addData.goods_data.push(addGood);
                    this.new_goods_data={
                        goods_name : '',
                        goods_number : '',
                        english_name:'',
                        goods_price : '',
                        goods_bianma : '',
                        goods_unit : '',
                        goods_unit_name:''
                    }
                },
                delGoods(row,index) {
                    this.addData.goods_data.splice(index,1);
                    // this.addData.good_list.splice(index,1)
                },
                computeWeight(){
                    if(this.applyLogisticsDialogFormState==-2 || !this.applyLogisticsDialogForm){
                        return false;
                    }
                    if(this.addData.long != '' && this.addData.long != 0 &&
                        this.addData.width != '' && this.addData.width != 0 &&
                        this.addData.height != '' && this.addData.height != 0
                    ) {
                        let ceil_weight = this.addData.long * this.addData.width * this.addData.height / 5000;
                        //体积重保留一位小数
                        ceil_weight_display = parseFloat(ceil_weight.toFixed(2));
                        this.addData.weight = ceil_weight_display; //体积重
                        let compute_weight = ceil_weight;
                        if(this.addData.real_weight != ''){
                            let real_weight=parseFloat(this.addData.real_weight)
                            if(ceil_weight > real_weight){
                                compute_weight = ceil_weight;
                            }else{
                                compute_weight = real_weight;
                            }
                        }else{
                            compute_weight = ceil_weight;
                        }
                        if (compute_weight > 20.5) {
                            var w = Math.ceil(compute_weight);
                        } else {
                            var w = Math.ceil(compute_weight);
                            if (w - compute_weight >= 0.5) {
                                w = w - 0.5;
                            }
                        }
                        this.addData.press_weight = w;
                    }else{
                        this.addData.weight = '';
                        this.addData.press_weight = '';
                        if(this.addData.real_weight != '') {
                            let real_weight=parseFloat(this.addData.real_weight)
                            if (real_weight > 20.5) {
                                var w = Math.ceil(real_weight);
                            } else {
                                var w = Math.ceil(real_weight);
                                if (w - real_weight >= 0.5) {
                                    w = w - 0.5;
                                }
                            }
                            this.addData.press_weight = w;
                        }else{
                            this.addData.press_weight = '';
                        }
                    }
                },
                handleSelectCountry(country) {
                    this.addData.region_name=country.value
                    this.addData.country_id = country.id;
                    this.addData.numberCode=country.code
                },
                searchCountry(country){
                    this.searchData.country_id=country.id;
                },
                handleSelectHsCode(hs_code) {
                    this.new_goods_data.goods_bianma = hs_code.value;
                },
                handleSelectCustomer(customer) {
                    // console.log(customer)
                    this.addData.customer_number = customer.number;
                    this.addData.customer_id = customer.id;
                    this.addData.customer_name = customer.customer_name;
                    this.addData.press_name = customer.customer_name;
                    if(customer.id!=0){
                         this.get_email_getters()
                            .then(res =>{

                            const email_getter = res.data.find((value)=>value.is_main == '1');
                            if(email_getter){
                                // this.addData.email_getter_name=(email_getter.customer_name2==null?email_getter.customer_name:email_getter.customer_name2)
                                this.addData.email_getter_name=(email_getter.customer_name)
                                this.addData.email_getter=email_getter.id
                                this.addData.email_getter_email=email_getter.email
                            }else {
                                // this.addData.email_getter_name=(res.data[0].customer_name2==null?res.data[0].customer_name:res.data[0].customer_name2)
                                this.addData.email_getter_name=(res.data[0].customer_name)
                                this.addData.email_getter=res.data[0].id
                                this.addData.email_getter_email=res.data[0].email
                            }
                            this.email_getter_array=res.data
                        })
                    }
                },
                get_email_getters(){
                    return http.get('/logistics/get_email_getters', {
                            params: {
                                id:this.addData.customer_id
                            }
                        })
                },
                get_email_getter(id){
                    return http.get('/logistics/get_email_getter', {
                        params: {id}
                    })
                },
                //通过客户id获取所有联系人
                handleGetEmailGetterByCustomerId(){
                        this.get_email_getters()
                        .then((res) => {
                            this.email_getter_array=res.data
                        })
                        .catch(() => {})
                },
                //选择邮件收取人
                handleSelectEmailGetter(item){
                    // this.addData.email_getter_name=item.customer_name2==null?item.customer_name:item.customer_name2
                    this.addData.email_getter_name=item.customer_name
                    this.addData.email_getter=item.id
                    this.addData.email_getter_email=item.email
                },
                handleSelectCustomerForm(customer) {
                    this.searchData.customer_id = customer.id;
                    this.searchData.customer_name=customer.customer_name
                },
                querySearchHsCode(queryString,cb) {
                    let result = this.hscodelist;
                    cb(result);
                },
                //获取所有地区
                getALlCountry() {
                    let params={}
                    axios.get('/api/logistics/regionlist', {
                        params: params
                    }).then((response)=>{
                        let list = [];
                        let country_list = response.data.data.list
                        country_list.forEach((item, key) => {
                            list.push({
                                value: item.region_english_name,
                                id: item.id,
                                code : item.country_code
                            });
                        })
                        this.allCountryList=list
                        this.searchCountryList=list
                        if(first_in>0){
                            return;
                        }
                        this.loadData();
                        first_in++;
                    });

                },
                querySearchCustomer(customer_name, type) {
                    if(customer_name==''){
                        customer_name=null
                    }
                    axios.get('/api/logistics/customer', {
                        params: {
                            customer_name: customer_name,
                            op_type:type
                        }
                    }).then(res=> {
                        // handle success
                        let list = [];
                        if(res.data.code==0){
                        res.data.data.forEach((item, key) => {
                            list.push({
                                customer_name: item.customer_name,
                                number: item.number,
                                id: item.id
                            });
                        })
                        if(type==0){
                        this.searchMoreCustomerList=list
                        }else{
                        this.searchCustomerList=list
                        }
                    }else{
                       this.$message({
                            type: 'error',
                            message: res.data.msg
                          });
                    }
                    });
                }
            }
        })
    </script>
<?php echo $this->render('/public/footer'); ?>
